﻿namespace c_基础项目
{

    internal class Program
    {
        static void Main(string[] args)
        {
            #region 1 控制台设置
            int w = 50;
            int h = 30;
            ConsoleInit(w, h);
            #endregion
            #region 2 场景
            Secece nowSecece = Secece.begin;
            while (true)
            {
                switch (nowSecece)
                {
                    case Secece.begin:
                     //开始场景
                     Console.Clear();
                        BeginSecence(w,h,ref nowSecece);
                      break;
                    case Secece.game:
                      //游戏场景
                      Console.Clear();
                        GameSence(w,h);
                      break;
                    case Secece.end:
                        //结束场景
                        Console.Clear();
                        break;
                    default:
                        break;
                }

            }
            #endregion
        }
        #region 1 控制台设置
        static void ConsoleInit(int w,int h)
        {
            //关闭光标
            Console.CursorVisible = false;
            //窗口大小和缓冲区大小
            Console.SetWindowSize(w,h);
            Console.SetBufferSize(w,h);
        }
        #endregion

        #region 3 场景切换
        static void BeginSecence(int w,int h,ref Secece nowSecece)
        {
            Console.SetCursorPosition(w / 2 - 3, 8);
            Console.Write("飞行棋");
            int NowSelindex = 0;
            bool isSececeGame=false;
            while (true)
            {
                Console.SetCursorPosition(w / 2 - 4, 13);
                Console.ForegroundColor=NowSelindex==0? ConsoleColor.Red:ConsoleColor.White;
                Console.Write("开始游戏");

                Console.SetCursorPosition(w / 2 - 4, 15);
                Console.ForegroundColor = NowSelindex == 1 ? ConsoleColor.Red : ConsoleColor.White;
                Console.Write("退出游戏");
                switch (Console.ReadKey(true).Key)
                {
                    case ConsoleKey.W:
                        NowSelindex--;
                        if (NowSelindex < 0)
                        {
                            NowSelindex = 0;
                        }
                        break;
                        case ConsoleKey.S:
                        NowSelindex++;
                        if (NowSelindex > 1)
                        {
                            NowSelindex = 1;
                        }
                        break;
                        case ConsoleKey.J:
                        if (NowSelindex == 0)
                        {
                            nowSecece = Secece.game;
                            isSececeGame = true;
                        }
                        else
                        {
                            Environment.Exit(0);
                        }
                        break;
                }
                if (isSececeGame == true)
                    break;
            }
        }
        #endregion
        #region 游戏场景
        static void GameSence(int w,int h)
        {
            //绘制不变信息
            DrawWall(w,h);
            //游戏逻辑
            Grid normal= new Grid(E_Grid.Normal,5,5);
            normal.Draw();
            while (true)
            {

            }
        }
        #endregion
        #region 4绘制不变信息
        static void DrawWall(int w,int h)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            for (int i = 0; i < w; i+=2)
            {//横着的墙
                Console.SetCursorPosition(i,0);
                Console.Write("■");
                Console.SetCursorPosition(i, h-1);
                Console.Write("■");
                Console.SetCursorPosition(i, h - 6);
                Console.Write("■");
                Console.SetCursorPosition(i, h - 11);
                Console.Write("■");
            }
            //竖着墙
            for (int j = 0; j < h; j++)
            {
                Console.SetCursorPosition(0, j);
                Console.Write("■");
                Console.SetCursorPosition(w - 2, j);
                Console.Write("■");
            }
            //文字信息
            Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(2, h - 10);
            Console.Write("□:普通格子");

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.SetCursorPosition(2, h - 9);
            Console.Write("‖:暂停，一回合不懂");

            Console.ForegroundColor = ConsoleColor.Red;
            Console.SetCursorPosition(26, h - 9);
            Console.Write("●:炸弹，倒退5格");

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.SetCursorPosition(2, h - 8);
            Console.Write("¤:时空隧道，随机倒退，暂停，换位置");

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.SetCursorPosition(2, h - 7);
            Console.Write("★:玩家");

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.SetCursorPosition(12, h - 7);
            Console.Write("▲:电脑");

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.SetCursorPosition(22, h - 7);
            Console.Write("◎:玩家和电脑重合");

            Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(2, h - 5);
            Console.Write("按任意键开始扔色子");
        }
        #endregion
    }


    #region 2 场景枚举
    enum Secece
    {
        begin,
        game,
        end,
    }
    #endregion
    #region 5格子的结构体和枚举
    enum E_Grid
    {
        Normal,
        Boom,
        Pause,
        Tunnel,
    }
    struct Vector2
    {
        public int w;
        public int h;
        public Vector2(int w, int h)
        {
            this.w = w; this.h = h;
        }
    };
    struct Grid
    {
        public E_Grid type;
        Vector2 pos;
        public Grid(E_Grid type, int w, int h)
        {
            this.type = type;
            pos.h = h;
            pos.w = w;
        }
        public void Draw()
        {
            Console.SetCursorPosition(pos.w, pos.h);
            switch (type)
            {
                case E_Grid.Normal:
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write("□");
                    break;
                case E_Grid.Boom:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("●");
                    break;
                case E_Grid.Pause:
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.Write("‖");
                    break;
                case E_Grid.Tunnel:
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write("¤");
                    break;
            }
        }
    };
    #endregion
}
